import math


def Spherical_cap(data: dict):
    """
    计算球缺，输入一个字典，返回一个字典
    :param data:字典
    {
    r: 球缺半径
    h: 球缺高度
    }

    :return res:字典
    {
    "Spherical_cap_volume"：球台体积
    "Spherical_cap_area"：球台面积
    }
    """
    if "r" in data and "h" in data:
        r = data["r"]
        h = data["h"]
        Spherical_cap_volume = math.pi * h * (3 * r * r + h * h) / 6
        Spherical_cap_area = 2 * math.pi * r * h
    else:
        pass
    return {
        "Spherical_cap_volume" : Spherical_cap_volume,
        "Spherical_cap_area" : Spherical_cap_area
    }


def test():
    """
    测试函数
    :return:
    """
    data = {
        "r": 2,
        "h": 2
    }
    res = Spherical_cap(data)
    print(res)


test()
